<?php

require_once("include/bittorrent.php");
dbconn();
loggedinorreturn();
if ($_GET['id'])
	stderr("派对结束了！", "这一招不管用了，你需要点击按钮！");
$userid = 0 + $CURUSER["id"];
$torrentid = 0 + $_POST["id"];
$arr = mysql_fetch_array(sql_query("SELECT owner FROM torrents where id = $torrentid"));
if (!$arr)
	stderr("错误", "不存在的种子");
$torrentowner = $arr['owner'];
$trows = mysql_num_rows(sql_query("SELECT id FROM thanks WHERE torrentid = $torrentid AND userid = $userid"));
if ($trows != 0)
	stderr("错误", "已经感谢过了！");
if (isset($userid) && isset($torrentid)) {
	$res = sql_query("INSERT INTO thanks (torrentid, userid) VALUES ($torrentid, $userid)");
	KPS("+", $saythanks_bonus, $CURUSER['id']); //User gets bonus for saying thanks
	KPS("+", $receivethanks_bonus, $torrentowner); //Thanks receiver get bonus
}